from socket import *
from threading import Thread


def recv_data():
    while True :
        recv_info = client_socket.recv(1024)
        recv_content = recv_info.decode()
        print(f"client say: {recv_content} , from: {client_info}")

        if recv_content == "over" :
            break

def send_data():
    while True:
        msg = input(">")
        client_socket.send(msg.encode())
        if msg == "over":
            print("finished connection")
            break

if __name__ == '__main__':
    server_socket = socket(AF_INET , SOCK_STREAM)

    server_socket.bind(("" , 8899))

    server_socket.listen(5)

    print("Server is running...")

    # 返回用于与该客户端进行数据通信的套接字
    client_socket , client_info = server_socket.accept()

    print("one client has connected success...")

    t1 = Thread(target = recv_data)
    t2 = Thread(target = send_data)

    t1.start()
    t2.start()

    t1.join()
    t2.join()

    client_socket.close()
    server_socket.close()